package controler;

import java.io.File;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JMenu;
import javax.swing.JMenuItem;

import controler.executors.Executor;
import controler.executors.QuitExecutor;

public enum ActionE {
	QUIT("Quit", "exit_manager.png", new QuitExecutor());
	
	private String description;
	private String iconName;
	private Executor executor = null;
	
	private ActionE(String description, String iconName, Executor executor) {
		this.description = description;
		this.iconName = iconName;
		this.executor = executor;
	}
	
	public boolean hasExecutor() {
		return executor!=null;
	}
	
	private ActionE(String description, String iconName) {
		this.description = description;
		this.iconName = iconName;
	}
	
	public void executeAction(Controler controler, String actionCommand) {
		executor.execute(controler);
	}
	
	public JMenuItem getMenuItem(Controler controler) {
		JMenuItem menuItem = new JMenuItem(description);
		menuItem.setActionCommand(this.toString());
		menuItem.addActionListener(controler);
		menuItem.setIcon(new ImageIcon(ClassLoader.getSystemClassLoader().getResource("data" + File.separator + iconName)));
		return menuItem;
	}
	
	public JMenu getMenu() {
		JMenu menu = new JMenu(description);
		menu.setIcon(new ImageIcon(ClassLoader.getSystemClassLoader().getResource("data" + File.separator + iconName)));
		return menu;
	}
	
	public JButton getActionButton(Controler controler) {
		JButton button = new JButton();
		button.addActionListener(controler);
		button.setActionCommand(this.toString());
		button.setIcon(new ImageIcon(ClassLoader.getSystemClassLoader().getResource("data" + File.separator + iconName)));
		button.setToolTipText(description);
		button.setFocusPainted(false);
		return button;
	}
	
}
